package com.ofhb.webapp.client.utils;

import java.util.Date;

import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;

public class AppClientUtils {

	public static AbsolutePanel getHorizontalSpacer(int height) {
		AbsolutePanel apSpacer = new AbsolutePanel();
		apSpacer.setSize("10px", height + "px");
		return apSpacer;
	}

	public static FlexTable getFieldErrorBox(String errorMessage) {
		FlexTable ftError = new FlexTable();
		ftError.setStyleName("ofhb-form-field-error-table");

		Image image = new Image("resources/images/field_error.png");
		ftError.setWidget(0, 0, image);
		image.setSize("16px", "16px");

		Label lbErrorMsg = new Label(errorMessage);
		ftError.setWidget(0, 1, lbErrorMsg);

		ftError.setVisible(false);

		return ftError;
	}

	public static ListBox getStatesListBox() {

		ListBox listBoxState = new ListBox();
		listBoxState.addItem("--Select One--");
		listBoxState.addItem("Andaman and Nicobar Islands", "AN");
		listBoxState.addItem("Andhra Pradesh", "AP");
		listBoxState.addItem("Arunachal Pradesh", "AR");
		listBoxState.addItem("Assam", "AS");
		listBoxState.addItem("Bihar", "BR");
		listBoxState.addItem("Chandigarh", "CH");
		listBoxState.addItem("Chhattisgarh", "CT");
		listBoxState.addItem("Dadra and Nagar Haveli", "DN");
		listBoxState.addItem("Daman and Diu", "DD");
		listBoxState.addItem("Delhi", "DL");
		listBoxState.addItem("Goa", "GA");
		listBoxState.addItem("Gujarat", "GJ");
		listBoxState.addItem("Haryana", "HR");
		listBoxState.addItem("Himachal Pradesh", "HP");
		listBoxState.addItem("Jammu and Kashmir", "JK");
		listBoxState.addItem("Jharkhand", "JH");
		listBoxState.addItem("Karnataka", "KA");
		listBoxState.addItem("Kerala", "KL");
		listBoxState.addItem("Lakshadweep", "LD");
		listBoxState.addItem("Madhya Pradesh", "MP");
		listBoxState.addItem("Maharashtra", "MH");
		listBoxState.addItem("Manipur", "MN");
		listBoxState.addItem("Meghalaya", "ML");
		listBoxState.addItem("Mizoram", "MZ");
		listBoxState.addItem("Nagaland", "NL");
		listBoxState.addItem("Odisha", "OR");
		listBoxState.addItem("Puducherry", "PY");
		listBoxState.addItem("Punjab", "PB");
		listBoxState.addItem("Rajasthan", "RJ");
		listBoxState.addItem("Sikkim", "SK");
		listBoxState.addItem("Tamil Nadu", "TN");
		listBoxState.addItem("Tripura", "TR");
		listBoxState.addItem("Uttarakhand", "UT");
		listBoxState.addItem("Uttar Pradesh", "UP");
		listBoxState.addItem("West Bengal", "WB");
		return listBoxState;
	}

	public static ListBox getSecurityQuestionsListBox() {
		ListBox listBoxSecurityQuestion = new ListBox();
		listBoxSecurityQuestion.addItem("--Select One--");
		listBoxSecurityQuestion.addItem("What is your pets name?");
		listBoxSecurityQuestion.addItem("What was the name of your first school?");
		listBoxSecurityQuestion.addItem("Who was your childhood hero?");
		listBoxSecurityQuestion.addItem("What is your favorite pass-time?");
		listBoxSecurityQuestion.addItem("What is your all-time favorite sports team?");
		listBoxSecurityQuestion.addItem("What is your fathers middle name?");
		listBoxSecurityQuestion.addItem("What was your high school mascot?");
		listBoxSecurityQuestion.addItem("What make was your first car or bike?");
		listBoxSecurityQuestion.addItem("Where did you first meet your spouse? ");
		return listBoxSecurityQuestion;
	}

	public static boolean isValidDate(int year, int month, int day) {
		boolean result = false;
		if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
				&& day <= 31) {
			result = true;
		} else if (month == 2) {
			boolean isLeapYear = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0));
			if (isLeapYear && day <= 29) {
				result = true;
			} else if (!isLeapYear && day <= 28) {
				result = true;
			}
		} else if (day <= 30) {
			result = true;
		}
		// System.out.println(day + " / " + month + " / " + year + " := " +
		// result);
		return result;
	}

	@SuppressWarnings("deprecation")
	public static Date getDate(int year, int month, int day) {
		Date dt = new Date(year, month, day);
		return dt;
	}

}
